/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package xcore.model.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

import xcore.constraint.XIntVar;

import xcore.model.ModelPackage;
import xcore.model.XAttFeature;
import xcore.model.XAttribute;
import xcore.model.XClass;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>XAtt Feature</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link xcore.model.impl.XAttFeatureImpl#getCardinality <em>Cardinality</em>}</li>
 *   <li>{@link xcore.model.impl.XAttFeatureImpl#getFrom <em>From</em>}</li>
 *   <li>{@link xcore.model.impl.XAttFeatureImpl#getXArttribute <em>XArttribute</em>}</li>
 *   <li>{@link xcore.model.impl.XAttFeatureImpl#getLowerBound <em>Lower Bound</em>}</li>
 *   <li>{@link xcore.model.impl.XAttFeatureImpl#getUpperBound <em>Upper Bound</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class XAttFeatureImpl extends EObjectImpl implements XAttFeature {
	/**
	 * The cached value of the '{@link #getCardinality() <em>Cardinality</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCardinality()
	 * @generated
	 * @ordered
	 */
	protected XIntVar cardinality;

	/**
	 * The cached value of the '{@link #getFrom() <em>From</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFrom()
	 * @generated
	 * @ordered
	 */
	protected XClass from;

	/**
	 * The cached value of the '{@link #getLowerBound() <em>Lower Bound</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLowerBound()
	 * @generated
	 * @ordered
	 */
	protected XIntVar lowerBound;

	/**
	 * The cached value of the '{@link #getUpperBound() <em>Upper Bound</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUpperBound()
	 * @generated
	 * @ordered
	 */
	protected XIntVar upperBound;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected XAttFeatureImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ModelPackage.Literals.XATT_FEATURE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public XIntVar getCardinality() {
		return cardinality;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetCardinality(XIntVar newCardinality, NotificationChain msgs) {
		XIntVar oldCardinality = cardinality;
		cardinality = newCardinality;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ModelPackage.XATT_FEATURE__CARDINALITY, oldCardinality, newCardinality);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCardinality(XIntVar newCardinality) {
		if (newCardinality != cardinality) {
			NotificationChain msgs = null;
			if (cardinality != null)
				msgs = ((InternalEObject)cardinality).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ModelPackage.XATT_FEATURE__CARDINALITY, null, msgs);
			if (newCardinality != null)
				msgs = ((InternalEObject)newCardinality).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ModelPackage.XATT_FEATURE__CARDINALITY, null, msgs);
			msgs = basicSetCardinality(newCardinality, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.XATT_FEATURE__CARDINALITY, newCardinality, newCardinality));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public XClass getFrom() {
		if (from != null && from.eIsProxy()) {
			InternalEObject oldFrom = (InternalEObject)from;
			from = (XClass)eResolveProxy(oldFrom);
			if (from != oldFrom) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, ModelPackage.XATT_FEATURE__FROM, oldFrom, from));
			}
		}
		return from;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public XClass basicGetFrom() {
		return from;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFrom(XClass newFrom) {
		XClass oldFrom = from;
		from = newFrom;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.XATT_FEATURE__FROM, oldFrom, from));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public XAttribute getXArttribute() {
		if (eContainerFeatureID != ModelPackage.XATT_FEATURE__XARTTRIBUTE) return null;
		return (XAttribute)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetXArttribute(XAttribute newXArttribute, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newXArttribute, ModelPackage.XATT_FEATURE__XARTTRIBUTE, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setXArttribute(XAttribute newXArttribute) {
		if (newXArttribute != eInternalContainer() || (eContainerFeatureID != ModelPackage.XATT_FEATURE__XARTTRIBUTE && newXArttribute != null)) {
			if (EcoreUtil.isAncestor(this, newXArttribute))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newXArttribute != null)
				msgs = ((InternalEObject)newXArttribute).eInverseAdd(this, ModelPackage.XATTRIBUTE__FEATURES, XAttribute.class, msgs);
			msgs = basicSetXArttribute(newXArttribute, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.XATT_FEATURE__XARTTRIBUTE, newXArttribute, newXArttribute));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public XIntVar getLowerBound() {
		return lowerBound;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetLowerBound(XIntVar newLowerBound, NotificationChain msgs) {
		XIntVar oldLowerBound = lowerBound;
		lowerBound = newLowerBound;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ModelPackage.XATT_FEATURE__LOWER_BOUND, oldLowerBound, newLowerBound);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLowerBound(XIntVar newLowerBound) {
		if (newLowerBound != lowerBound) {
			NotificationChain msgs = null;
			if (lowerBound != null)
				msgs = ((InternalEObject)lowerBound).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ModelPackage.XATT_FEATURE__LOWER_BOUND, null, msgs);
			if (newLowerBound != null)
				msgs = ((InternalEObject)newLowerBound).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ModelPackage.XATT_FEATURE__LOWER_BOUND, null, msgs);
			msgs = basicSetLowerBound(newLowerBound, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.XATT_FEATURE__LOWER_BOUND, newLowerBound, newLowerBound));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public XIntVar getUpperBound() {
		return upperBound;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetUpperBound(XIntVar newUpperBound, NotificationChain msgs) {
		XIntVar oldUpperBound = upperBound;
		upperBound = newUpperBound;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ModelPackage.XATT_FEATURE__UPPER_BOUND, oldUpperBound, newUpperBound);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUpperBound(XIntVar newUpperBound) {
		if (newUpperBound != upperBound) {
			NotificationChain msgs = null;
			if (upperBound != null)
				msgs = ((InternalEObject)upperBound).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ModelPackage.XATT_FEATURE__UPPER_BOUND, null, msgs);
			if (newUpperBound != null)
				msgs = ((InternalEObject)newUpperBound).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ModelPackage.XATT_FEATURE__UPPER_BOUND, null, msgs);
			msgs = basicSetUpperBound(newUpperBound, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.XATT_FEATURE__UPPER_BOUND, newUpperBound, newUpperBound));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ModelPackage.XATT_FEATURE__XARTTRIBUTE:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetXArttribute((XAttribute)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ModelPackage.XATT_FEATURE__CARDINALITY:
				return basicSetCardinality(null, msgs);
			case ModelPackage.XATT_FEATURE__XARTTRIBUTE:
				return basicSetXArttribute(null, msgs);
			case ModelPackage.XATT_FEATURE__LOWER_BOUND:
				return basicSetLowerBound(null, msgs);
			case ModelPackage.XATT_FEATURE__UPPER_BOUND:
				return basicSetUpperBound(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID) {
			case ModelPackage.XATT_FEATURE__XARTTRIBUTE:
				return eInternalContainer().eInverseRemove(this, ModelPackage.XATTRIBUTE__FEATURES, XAttribute.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ModelPackage.XATT_FEATURE__CARDINALITY:
				return getCardinality();
			case ModelPackage.XATT_FEATURE__FROM:
				if (resolve) return getFrom();
				return basicGetFrom();
			case ModelPackage.XATT_FEATURE__XARTTRIBUTE:
				return getXArttribute();
			case ModelPackage.XATT_FEATURE__LOWER_BOUND:
				return getLowerBound();
			case ModelPackage.XATT_FEATURE__UPPER_BOUND:
				return getUpperBound();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ModelPackage.XATT_FEATURE__CARDINALITY:
				setCardinality((XIntVar)newValue);
				return;
			case ModelPackage.XATT_FEATURE__FROM:
				setFrom((XClass)newValue);
				return;
			case ModelPackage.XATT_FEATURE__XARTTRIBUTE:
				setXArttribute((XAttribute)newValue);
				return;
			case ModelPackage.XATT_FEATURE__LOWER_BOUND:
				setLowerBound((XIntVar)newValue);
				return;
			case ModelPackage.XATT_FEATURE__UPPER_BOUND:
				setUpperBound((XIntVar)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ModelPackage.XATT_FEATURE__CARDINALITY:
				setCardinality((XIntVar)null);
				return;
			case ModelPackage.XATT_FEATURE__FROM:
				setFrom((XClass)null);
				return;
			case ModelPackage.XATT_FEATURE__XARTTRIBUTE:
				setXArttribute((XAttribute)null);
				return;
			case ModelPackage.XATT_FEATURE__LOWER_BOUND:
				setLowerBound((XIntVar)null);
				return;
			case ModelPackage.XATT_FEATURE__UPPER_BOUND:
				setUpperBound((XIntVar)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ModelPackage.XATT_FEATURE__CARDINALITY:
				return cardinality != null;
			case ModelPackage.XATT_FEATURE__FROM:
				return from != null;
			case ModelPackage.XATT_FEATURE__XARTTRIBUTE:
				return getXArttribute() != null;
			case ModelPackage.XATT_FEATURE__LOWER_BOUND:
				return lowerBound != null;
			case ModelPackage.XATT_FEATURE__UPPER_BOUND:
				return upperBound != null;
		}
		return super.eIsSet(featureID);
	}

} //XAttFeatureImpl
